package com.lkyh.pad;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.widget.ImageView;
import android.widget.Toast;

public class PadLaunchActivity extends AppCompatActivity {
    //记录用户首次点击返回键的时间
    private long firstTime = 0;
    private ImageView imageSz;
    private ImageView imageBtn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.pad_launch_activity);
        imageSz = findViewById(R.id.image_sz);
        imageSz.setOnClickListener((v) -> {
            Intent settingIntent = new Intent(PadLaunchActivity.this, SettingActivity.class);
            PadLaunchActivity.this.startActivity(settingIntent);
        });

        imageBtn = findViewById(R.id.imageBtn);
        imageBtn.setOnClickListener((v) -> {
            //抬起时启动定时
            Intent mainIntent = new Intent(PadLaunchActivity.this, MainActivity.class);
            PadLaunchActivity.this.startActivity(mainIntent);
            //PadLaunchActivity.this.finish();
        });

    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            long secondTime = System.currentTimeMillis();
            if (secondTime - firstTime > 2000) {
                Toast.makeText(PadLaunchActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                firstTime = secondTime;
                return true;
            } else {
                finish();
            }
        }
        return super.onKeyDown(keyCode, event);
    }
/*
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:

            case MotionEvent.ACTION_UP:
                //抬起时启动定时
                Intent mainIntent = new Intent(PadLaunchActivity.this, MainActivity.class);
                PadLaunchActivity.this.startActivity(mainIntent);
                PadLaunchActivity.this.finish();
                break;

        }
        return super.dispatchTouchEvent(ev);

    }*/


}
